﻿#include <iostream>
2 #include <string.h>
3 using namespace std;
4
5 const int N = 1010;
6
7 int n, V, v[N], w[N];
8 int dp[N][N];
9
10 int main()
11 {
12 // 读⼊数据
13 cin >> n >> V;
14 for(int i = 1; i <= n; i++) 
15 cin >> v[i] >> w[i];
16 
17 // 第⼀问
18 for(int i = 1; i <= n; i++)
19 for(int j = 0; j <= V; j++)
20 {
21 dp[i][j] = dp[i - 1][j];
22 if(j >= v[i]) dp[i][j] = max(dp[i][j], dp[i][j - v[i]] + w[i]);
23 }
24 
25 cout << dp[n][V] << endl;
26
27 // 第⼆问
28 memset(dp, 0, sizeof dp);
29 for(int j = 1; j <= V; j++) dp[0][j] = -1;
30 for(int i = 1; i <= n; i++)
31 for(int j = 0; j <= V; j++)
32 {
33 dp[i][j] = dp[i - 1][j];
34 if(j >= v[i] && dp[i][j - v[i]] != -1) 
35 dp[i][j] = max(dp[i][j], dp[i][j - v[i]] + w[i]);
36 }
37 
38 cout << (dp[n][V] == -1 ? 0 : dp[n][V]) << endl;
39
40 return 0;
41 }